package com.woniuxy.controller;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 如果在springmvc2.5之前开发后置控制器（也称为Handle）只有一个办法
 * 需要自定义Java类，实现Controller接口
 */
public class HelloController implements Controller {
    @Override
    public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        //实例化ModelAndView对象
        ModelAndView modelAndView=new ModelAndView();
        //相当于request.setAttribute(key,value)将数据保存到request范围对象中
        modelAndView.addObject("msg","Hello Controller handeRequest");
        //跳转路径,属于转发类型的跳转
        modelAndView.setViewName("welcome");
        return modelAndView;
    }
}
